<template>
  <div v-loading="loading">
    <el-form ref="form" :model="form" :rules="rules" label-width="120px" class="dataForm">
      <el-row>
        <el-col :span="24">
          <el-form-item :label="$t('基金名称')" prop="fundName">
            <!--            <el-input v-model="form.fundName" :placeholder="$t('基金名称')" show-word-limit maxlength="32" />-->
            <template>
              <router-link
                target="_blank"
                :to="{path:'/fund/fundBasehome',query:{id:form.fundId}}"
                class="link_a"
              >{{ form.fundName }}
              </router-link>
            </template>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金管理人')" prop="fundManager">
            <el-select v-model="form.fundManager" filterable clearable :placeholder="$t('请选择')" disabled>
              <el-option
                v-for="item in gpBaseOptions"
                :key="item.id"
                :label="item.name"
                :value="item.id"
                disabled
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金成立日')" prop="foundationDate">
            <el-date-picker
              v-model="form.foundationDate"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('基金成立日')"
              disabled
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('基金规模') + $t('金额单位')" prop="fundSize">
            <Money v-model="form.fundSize" unit="w" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('清算开始时间')" prop="liquidationStartTime">
            <el-date-picker
              v-model="form.liquidationStartTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('清算开始时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('清算结束时间')" prop="liquidationEndTime">
            <el-date-picker
              v-model="form.liquidationEndTime"
              clearable
              style="width: 200px"
              type="date"
              value-format="yyyy-MM-dd"
              :placeholder="$t('清算结束时间')"
            />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('清算次数')" prop="liquidationsNumber">
            <el-input v-model="form.liquidationsNumber" :placeholder="$t('清算次数')" show-word-limit maxlength="32" />
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item :label="$t('清算组人员')" prop="liquidationTeam">
            <UserSelect v-model="form.liquidationTeam" filterable multiple :placeholder="$t('接收用户')" />
          </el-form-item>
        </el-col>
      </el-row>
      <FileTable
        :list.sync="form.fileList"
        data-type="fund_wf_liquidation"
        :business-id="autoBusinessId($route.query.id, form)"
        :btn-show="!otherBtnHide"
      />
    </el-form>
  </div>
</template>

<script>
import { saveFundWfLiquidation, getFundWfLiquidation, getFundSize } from '@/api/fund/liquidation/fundWfLiquidation'
    import { getFundBase } from '@/api/fund/fundBase'
    import { findGp } from '@/api/fund/gp/gpBase'
    export default {
        data() {
            return {
                // 表单参数
                form: {},
                // 表单校验
                rules: {
                  fundSize: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  liquidationStartTime: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  liquidationEndTime: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  liquidationsNumber: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }],
                  liquidationTeam: [{ required: true, message: this.$t('必填信息'), trigger: 'blur' }]

                },
                // 遮罩层
                loading: false,
                // 操作按钮默认不展示
                buttonShow: true,
                otherBtnHide: false,
                // 基金管理人
                gpBaseOptions: []
            }
        },
        created() {
            this.$bus.$emit('async_done')
            // 查询基金管理人
            this.findGpOption()
        },
        methods: {
            // 初始化数据
            init(data) {
                this.loading = true
                if (data != null && data.id !== undefined) {
                    getFundWfLiquidation(data.id).then(response => {
                        this.form = response.data
                        this.loading = false
                    }).catch(() => {
                        this.loading = false
                    })
                } else {
                    this.reset()
                    if (data != null) {
                      this.form.fileList = data.fileList
                    }
                    getFundBase(this.$route.query.id).then(response => {
                      this.form.fundName = response.data.fundFullName
                      this.form.foundationDate = response.data.foundationDate
                      this.form.fundManager = response.data.fundBaseFund.managerId
                      getFundSize(this.$route.query.id).then(response => {
                        this.form.fundSize = response.data
                        this.loading = false
                      })
                    }).catch(() => {
                      this.loading = false
                    })
                }
            },
            // 表单重置
            reset() {
                this.form = {
                    id: undefined,
                    fundId: this.$route.query.id,
                    fundName: undefined,
                    fundManager: undefined,
                    foundationDate: undefined,
                    fundSize: undefined,
                    liquidationStartTime: undefined,
                    liquidationEndTime: undefined,
                    liquidationsNumber: undefined,
                    liquidationTeam: [],
                    createBy: undefined,
                    createTime: undefined,
                    updateBy: undefined,
                    updateTime: undefined,
                    delFlag: undefined
                }
                this.resetForm('form')
            },
            // 取消按钮
            cancel() {
                this.$parent.$parent.formOpen = false
                this.$parent.$parent.reset()
            },
            // 关闭form页面
            closeForm() {
                // 关闭form页面遮罩层
                this.loading = false
                // 关闭form页面
                if (this.$parent.$parent.formOpen !== undefined) {
                    this.$parent.$parent.formOpen = false
                }
                // 刷新list页面
                if (this.$parent.$parent.getList !== undefined) {
                  this.$parent.$parent.getList()
                }
            },
            /** 提交按钮 */
            submitForm: function() {
                return new Promise((resolve, reject) => {
                  this.$refs['form'].validate(valid => {
                    // 验证数据
                    if (valid) {
                      // 弹出遮罩层
                      this.loading = true
                      // 保存数据
                      saveFundWfLiquidation(this.form).then(response => {
                        if (response.code === 200) {
                          this.msgSuccess(this.$t('保存成功'))
                          this.loading = false
                          resolve(response.data.id)
                        } else {
                          this.msgError(response.msg)
                          this.loading = false
                          reject(response)
                        }
                      })
                    } else {
                      this.locationError(document)
                      reject()
                    }
                  })
                })
           },
          findGpOption() {
            findGp().then(response => {
              this.gpBaseOptions = response.data
            })
          }

        }

    }
</script>
